*********** Introduction

This is a self-contained folder to replicate the Figures and Tables of "Going Viral: Public Attention and Environmental Action in the Amazon", 
Rafael Araujo, Francisco Costa, Teevrat Garg.

We use Python and Stata. The Python code is presented in a JupyterNotebook, so that you can visualize its outputs directly there.
All outputs (figures and tables) will also be saved in the Output folder.

The only input from the user is the local directory paths located at the top of the codes.

*********** Hardware

You will need at least 72 Gb of ram to run this package.
The code should take approximately one day to run (23 hours).

*********** Steps to reproduce the paper:

Installing:

1 - Download your favorite Python distribution, we recommend the anaconda distribution. The code used Python 3.8.5

2 - Install the packages. The libraries are standard in Python and GIS Python:
	numpy 1.19.2
	pandas 1.1.3 
	matplotlib 3.3.2
	rasterio 1.1.8
	geopandas 0.7.0
	jupyter 1.1.0

If you are going to reproduce this paper using different library versions than the ones indicated: 
	any recent version of numpy, pandas, datetime, matplotlib, os, jupyter will work
	the challenge is getting compatible versions of rasterio and geopandas
We recommend the conda-forge channel if you are going to use different versions


3 - Install your Stata. Any version >= 14 works.

Running code:

4 - Run the Stata codes in the Code folder. There is no particular order for it. The codes are:
	Table1
	Table2
	RDD_SyntheticControl
	Dynamic_diffindiffs_weekly
	Dynamic_diffindiffs 

5 - Run Figures_Tables.ipynb

That is it, all outputs are saved in the Output folder.

*********** Description of outputs

*** Figures, (generated by):

 'Figure1_a.pdf', (Figures_Tables.ipynb)
 'Figure1_a.png', (Figures_Tables.ipynb)
 'Figure1_b.pdf', (Figures_Tables.ipynb)
 'Figure1_b.png', (Figures_Tables.ipynb)
 'Figure1_c.pdf', (Figures_Tables.ipynb)
 'Figure1_c.png', (Figures_Tables.ipynb)
 'Figure1_d.pdf', (Figures_Tables.ipynb)
 'Figure1_d.png', (Figures_Tables.ipynb)
 'Figure2_ab.pdf', (Figures_Tables.ipynb)
 'Figure2_ab.png', (Figures_Tables.ipynb)
 'Figure3_a.pdf', (Figures_Tables.ipynb with inputs from Dynamic_diffindiffs.do)
 'Figure3_a.png', (Figures_Tables.ipynb with inputs from Dynamic_diffindiffs.do)
 'Figure3_b.pdf', (Figures_Tables.ipynb)
 'Figure3_b.png', (Figures_Tables.ipynb)
 'Figure4_a.pdf', (Figures_Tables.ipynb)
 'Figure4_a.png', (Figures_Tables.ipynb)
 'Figure4_b.pdf', (Figures_Tables.ipynb)
 'Figure4_b.png', (Figures_Tables.ipynb)
 'Figure4_c.pdf', (Figures_Tables.ipynb)
 'Figure4_c.png', (Figures_Tables.ipynb)
 'FigureA1.pdf', (Figures_Tables.ipynb)
 'FigureA1.png', (Figures_Tables.ipynb)
 'FigureA2.pdf', (Figures_Tables.ipynb)
 'FigureA2.png', (Figures_Tables.ipynb)
 'FigureA3.pdf', (Figures_Tables.ipynb)
 'FigureA3.png', (Figures_Tables.ipynb)
 'FigureA4_a.pdf', (Figures_Tables.ipynb)
 'FigureA4_a.png', (Figures_Tables.ipynb)
 'FigureA4_b.pdf', (Figures_Tables.ipynb)
 'FigureA4_b.png', (Figures_Tables.ipynb)
 'FigureA5_a.pdf', (Figures_Tables.ipynb with inputs from Dynamic_diffindiffs.do)
 'FigureA5_a.png', (Figures_Tables.ipynb with inputs from Dynamic_diffindiffs.do)
 'FigureA5_b.pdf', (Figures_Tables.ipynb with inputs from Dynamic_diffindiffs_weekly.do)
 'FigureA5_b.png', (Figures_Tables.ipynb with inputs from Dynamic_diffindiffs_weekly.do)
 'FigureA5_c.pdf', (Figures_Tables.ipynb with inputs from RDD_SyntheticControl.do)
 'FigureA5_c.png', (Figures_Tables.ipynb with inputs from RDD_SyntheticControl.do)
 'FigureA6_a.pdf', (Figures_Tables.ipynb)
 'FigureA6_a.png', (Figures_Tables.ipynb)
 'FigureA6_b.pdf', (Figures_Tables.ipynb)
 'FigureA6_b.png', (Figures_Tables.ipynb)
 'FigureA7_a.pdf', (RDD_SyntheticControl.do)
 'FigureA7_b.pdf', (RDD_SyntheticControl.do)
 'FigureA8.pdf', (Figures_Tables.ipynb)
 'FigureA8.png' (Figures_Tables.ipynb)

*** Tables, (generated by):

'Table_1.tex', (Table1.do)
'Table_2.tex', (Table2.do)
'Table_A1.tex', (Figures_Tables.ipynb)
'Table_A2.tex', (Figures_Tables.ipynb with inputs from Dynamic_diffindiffs.do) 

*********** Description of codes

Figures_Tables.ipynb plots figures and tables
Table1.do generates Table 1 in the paper
Table2.do generates Table 2 in the paper
RDD_SyntheticControl.do generates the RDD figures (A7a,A7b) and the estimates of the Synthetic Control
Dynamic_diffindiffs.do generates the event-study of Table A1, Figures A5a, Figure 3a, Figure 3b
Dynamic_diffindiffs_weekly.do generates the event-study of Figure A5b

*********** Data

All data used and its sources are described in the paper. We summarize it here:

Public attention data is from Google Trends. 
Folder: \Input\gtrends
		\consolidado.csv - google trends data on amazon and fires
		\Smoke_saopaulo.csv - google trends on São Paulo's pollution


Data on The New York Time and The Guardian is from their own API
Folder: \Input\gtrends
		\NYtimes_Guardian_fires_amazon_Brazil_forest - data on hits of NYTimes and The Guardian

Fire data is from Fire Information for Resource Management System, FIRMS. 
Folders: \Input\Fire_years, \Input\raster_fire, \Input\panel

Burned area data is from the MODIS Burned Area Monthly Global
Folder: \Input\panel

Precipitation data is from ERA5 produced by the European Centre for Medium-Range Weather Forecasts. 
Folder: \Input\panel

Country borders and the limits of the Brazilian Amazon biome and Brazilian municipalities are from the Brazilian Institute of Geography and Statistics (IBGE)
Folders:\Input\raster_shapes
		\raster_of... is the raster of the shape (Amazon-Bolivia,Peru,Brazi; Brazilian municipalities; provinces in Bolivia)
		\idx_to_code_mun.csv connects a point in the raster with a Brazilian municipality
	\Input\shapes
		Shapefiles of Amazon_Bolivia, Amazon_Peru, Amazon in Brazil (Amazonia)

Data on fire brigades at the municipal level for the year 2019 from the Registry of Fire Incidents from the Environmental Agency  (ROI/IBAMA)
Folder: \Input\brigades, \Input\panel

Data on votes at the presidential election of 2018 is from the Brazilian Superior Electoral Court
Folder: \Input\votos
		\votes_bolsonaro.dta

Data on pollution is from the Environmental Company of the State of São Paulo
Folder: \Input\pollution
		\2016, \2017, \2018, \2019, \2020 pollution per year
		\mp252020, pollution 2020
		\Pollution, pollution 2016-2019
 

Data on congressional speeches is from the The Chamber of Deputies
Folder: as it is a small dataset it is stored as a dictionary in our jupyter notebook

*** Additional input description

All files in the folder \Input\panel concatenates the data used in the paper. Most columns are self-explanatory, here we describe the ones that are not
	
panel_no_time.csv - data on the cross-section 
		columns: 'index' 'distance_to_Amazonia' 'distance_to_Bolivia' 'distance_to_Peru' 'forest_mapbiomas' 'longitude' 'latitude' 'CD_GEOCMU'
		'index' is the id of the pixel, 'forest_mapbiomas' is share of forest cover, 'CD_GEOCMU' is the municipality code
	
	panel_time.csv - data that varies with time
		columns: 'index' 'fire' 'precipitation' 'brightness' 'week'
		

	panel_reg.csv - panel data with panel_time and panel_no_time
		columns: 'index' 'ref_week' 'fire_avg' 'brightness_avg' 'fire' 'precipitation' 'brightness' 'country_id' 'cluster' 'CD_GEOCMU' 'forest_mapbiomas' 'coef_week'
		'ref_week' is the week of the data, 'coef_week' is the bi-week, 'cluster' flag pixels inside the 25km x 25km cluster

	panel_rdd.csv - same as panel_reg but only with pixels close to the borders

	panel_reg_bolprov.csv - same as panel_reg but excluding the two provinces in Bolivia

	panel_reg_sample.csv - same as panel_reg but smaller. This is used only for the weekly event-study

	panel_syn.csv - aggregated panel data for the synthetic control
		columns: 'country_id' 'coef_week_s' 'fire' 'fire_avg' 'precipitation'

	panel_reg_burned.csv - monthly panel for the burned area event-study
		columns: 'burned' 'precipitation' 'index' 'year' 'month' 'country_id' 'cluster' 'burned_avg'

	week_to_date.csv - used only to store a function that maps number of the week with calendar date


